package com.example.sales_svc.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.example.sales_svc.model.AuctionAsset;
import com.example.sales_svc.service.AuctionAssetService;

@RestController
@RequestMapping("/api/assets")
public class AuctionAssetController {

    @Autowired
    private AuctionAssetService service;

    @PostMapping("/create")
    public ResponseEntity<AuctionAsset> create(@RequestBody AuctionAsset asset) {
        return ResponseEntity.ok(service.createAsset(asset));
    }

    @PostMapping("/status")
    public ResponseEntity<AuctionAsset> updateStatus(@RequestParam Long id, @RequestParam String status) {
        return ResponseEntity.ok(service.updateStatus(id, status));
    }

    @GetMapping("/list")
    public ResponseEntity<List<AuctionAsset>> getAll() {
        return ResponseEntity.ok(service.findAll());
    }

    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        service.delete(id);
        return ResponseEntity.noContent().build();
    }
}
